package com.yfz.day04;

/**
 *  209 长度最小的子数组
 */
class Solution {
    public int minSubArrayLen(int target, int[] nums) {
        int minLen = Integer.MAX_VALUE;
        int sum = 0;
        int start = 0;
        for (int end = 0; end < nums.length; end++)
        {
            sum+= nums[end];
            while(sum >= target && start <= end)
            {
                minLen = Math.min(minLen,end - start +1);
                sum -= nums[start++];
            }
        }
        return minLen == Integer.MAX_VALUE ?0 :minLen;
    }
}